package org.project.areader.view.adapter;

import org.project.areader.activity.R;
import org.project.areader.util.Global;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * @author robin
 * @date 2011-3-21
 * 
 */
public class BookMarksAdapter extends BaseAdapter
{
	private Context _context;
	private LayoutInflater mInflater;
	private int[] _title, _content, _height, _textsize;
	private int[][] _images;

	public BookMarksAdapter(Context context, int[] title, int[] content, int[] height, int[] textsize, int[][] images)
	{
		if (title.length != content.length)
		{
			Log.e(Global.TAG, "DirectoryAdapter.class title.length != content.length");
		}

		this._context = context;
		this._title = title;
		this._height = height;
		this._content = content;
		this._textsize = textsize;
		this._images = images;
		mInflater = LayoutInflater.from(context);
	}

	public int getCount()
	{

		return this._title.length;
	}

	public Object getItem(int position)
	{

		return this._title[position];
	}

	public long getItemId(int position)
	{

		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent)
	{

		ImageView image;
		TextView text;
		if (convertView == null)
		{
			convertView = mInflater.inflate(R.layout.bookmarks_row, null);

		}

		image = (ImageView) convertView.findViewById(R.id.bookmarks_rowimage);
		text = (TextView) convertView.findViewById(R.id.bookmarks_rowtext);

		image.setImageBitmap(BitmapFactory.decodeResource(_context.getResources(), R.drawable.directrow_d));
		text.setText(_context.getString(_title[position]));

		return convertView;
	}

	public int[][] getContent(int position)
	{
		int[][] id = new int[][]
		{
		{ _title[position] },
		{ _content[position] },
		{ _height[position] },
		{ _textsize[position] }, _images[position] };
		return id;
	}
}
